//
//  MainTableHeaderView.m
//  ProjectforHDX
//
//  Created by wuhf on 18/6/08.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "CunquHomeHeadView.h"
#import "StockInquiryVC.h"

#define   HEADER_HEIGHT 200

#define  MREO_HEIGHT 35
#define   BTN_HEIGHT 90

@interface CunquHomeHeadView()


@property(nonatomic,strong) NSMutableArray  *ArrayValue;//按钮文字

@property(nonatomic,strong) NSArray * typeArray;//数据数组
@end
@implementation CunquHomeHeadView

-(id)initHeaderView:(NSArray*)typeArray{
    self=[super initWithFrame:CGRectMake(0, 0, BOUNDSWIDTH, HEADER_HEIGHT)];
    if(self){
        self.typeArray=typeArray;
        
        self.backgroundColor= [UtilCheck hexStringToColor:@"1F62D2" alpha:1];
        
        [self createTypeView];
        [self createBtnView];
        [self createMoreView];
    }
    return self;
}



-(void)setValueArray:(NSArray*)array{
    
    for(int i=0;i<array.count;i++){
        
        if(i<self.ArrayValue.count){
            NSDictionary *dict=[array objectAtIndex:i];
            RZCustomLable *labValue=(RZCustomLable*)self.ArrayValue[i];
            labValue.text=[NSString stringWithFormat:@"%@",[dict objectForKey:@"count"]];
        }
        
    }
}



/**
 *  创建新建、库存查询按钮
 */
-(void)createTypeView{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height -BTN_HEIGHT-MREO_HEIGHT)];
    
    [view setBackgroundColor:[UtilCheck getRZColor:35 green:102 blue:207 alpha:1]];
    
    [self addSubview:view];
    THUserInfoModel *userModel=[THMangerTool getAccountInfo];
    
    if (![userModel.operationPermissions isKindOfClass:[NSArray class]]) {
        return;
    }
    NSInteger count = 4;
    CGFloat width=(view.width-(count+1) * 10)/(CGFloat)count;
    NSArray *titleArr1 = @[@"存件",@"存件",@"取件",@"取件"];
    NSArray *titleArr2 = @[[UtilCheck language:@"CachVC.Goodpieces"],[UtilCheck language:@"CachVC.Badpieces"],[UtilCheck language:@"CachVC.PickGoodpieces"],[UtilCheck language:@"CachVC.PickBadpieces"]];
    for(int i=0;i<count;i++){
        UIImage *image = [UIImage imageNamed:titleArr1[i]];
        NSString *title=[THMangerTool language:titleArr2[i]];
//        NSInteger type=[userModel.operationPermissions[i] intValue];
//        NSLog(@"操作权限是%ld",(long)type);
        
        OperationView *optionView=[[OperationView alloc] initOperationFrame:CGRectMake(10*(i+1)+width*i,10, width+10, view.height-20) icon:image title:title ];
        
        optionView.tag=200+i;
        UITapGestureRecognizer *tapv=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapView:)];
        tapv.view.tag=optionView.tag;
        [optionView addGestureRecognizer:tapv];
        [view addSubview:optionView];
        
    }
    
    
}
/**
 *  创建中间的按钮
 */
-(void)createBtnView{
    self.ArrayValue=[[NSMutableArray alloc] initWithCapacity:0];
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, self.height-BTN_HEIGHT-MREO_HEIGHT+50, self.width, BTN_HEIGHT-30)];
    [view setBackgroundColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1]];
    [self addSubview:view];
    
    UIButton *cunjianButon = [UIButton buttonWithType:UIButtonTypeCustom];
    [cunjianButon setTitle:[UtilCheck language:@"cunquDetail.Recentlysaved"] forState:0];
    cunjianButon.backgroundColor  =[UIColor whiteColor];
    cunjianButon.tag = 666;
    [cunjianButon addTarget:self action:@selector(recentAction:) forControlEvents:UIControlEventTouchUpInside];
    [cunjianButon setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    cunjianButon.frame = CGRectMake(0, 0, SCREEN_WIDTH/2, BTN_HEIGHT-30);
    [view addSubview:cunjianButon];
    
    UIImageView *botomView = [[UIImageView alloc]initWithFrame:CGRectMake( SCREEN_WIDTH/4-40, BTN_HEIGHT-30-2, 80, 2)];
    botomView.tag = 1000;
    botomView.backgroundColor = SYSTEM_COLOR;
    [view addSubview:botomView];
    
    UIButton *qujianButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [qujianButton setTitle:[UtilCheck language:@"cunquDetail.Recentlypickedup"] forState:0];
    qujianButton.tag = 888;
    [qujianButton addTarget:self action:@selector(recentAction:) forControlEvents:UIControlEventTouchUpInside];
    [qujianButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    qujianButton.frame = CGRectMake(SCREEN_WIDTH/2, 0, SCREEN_WIDTH/2, BTN_HEIGHT-30);
    [view addSubview:qujianButton];
    
    
}
#pragma mark 最近存件和最近取件安妞点击
- (void)recentAction:(UIButton *)but{
    UIImageView *bottomimageView = [self viewWithTag:1000];
    if(but.tag==666){
        if(self.viewblock){
            self.viewblock(NSButtonCunjianList);
        }
        [UIView animateWithDuration:0.45 animations:^{
            bottomimageView.frame = CGRectMake(SCREEN_WIDTH/4-40, BTN_HEIGHT-30-2, 80, 2);
        }];
    }
    else{
        if(self.viewblock){
            self.viewblock(NSButtonQujianList);
        }
        
        [UIView animateWithDuration:0.45 animations:^{
            bottomimageView.frame = CGRectMake( SCREEN_WIDTH/4-40+SCREEN_WIDTH/2, BTN_HEIGHT-30-2, 80, 2);
        }];
    }
}
    
-(void)tapView:(UITapGestureRecognizer*)recognizer{
    switch (recognizer.view.tag) {
        case 200:
        {
            if(self.viewblock){
                self.viewblock(NSButtonCunjianNice);
            }
        }
            break;
        case 201:
        {
            if(self.viewblock){
                self.viewblock(NSButtonCunjianBad);
            }
        }
            break;
        case 202:
        {
            if(self.viewblock){
                self.viewblock(NSButtonQujianNice);
            }
        }
            break;
        case 203:
        {
            if(self.viewblock){
                self.viewblock(NSButtonQujianBad);
            }
        }
            break;
        default:
            break;
    }
    
}

-(void)createMoreView{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, self.height-MREO_HEIGHT+20, self.width, MREO_HEIGHT-20)];
    
    UILabel *UpLine = [[UILabel alloc]init];
    [UpLine setFrame:CGRectMake(0, 0, self.width, 0.5)];
    [UpLine setBackgroundColor:[Toolobject getColorByHexString:@"#e5e5e5" alpha:1]];
    [view addSubview:UpLine];
    [view setBackgroundColor:[UtilCheck getRZColor:244 green:248 blue:251 alpha:1]];
    [self addSubview:view];
    
    
    [self addSubview:view];
}
- (void)deliveryReport:(RZCustomButtom*)sender {
    switch (sender.tag) {
        case 101:
        {
            if(self.viewblock){
                self.viewblock(NSButtonShipmentReport);
            }
        }
            break;
            
        default:
            break;
    }
}
-(void)btnClick:(RZCustomButtom*)sender{
    switch (sender.tag) {
        case 101:
        {
            if(self.viewblock){
                self.viewblock(NSButtonMore);
            }
        }
            break;
            
        default:
            break;
    }
}

@end

